package com.ccsu.joysport.config;

import io.jsonwebtoken.InvalidClaimException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

@Slf4j
@Component
public class TeacherInterceptor implements HandlerInterceptor {


    /**
     * 校验老师是否登录（jwt校验）
     *
     * @param request  请求
     * @param response 响应
     * @param handler  handler
     * @return true or false
     */
    @Override
    public boolean preHandle(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Object handler) throws Exception {

        try {

            // todo 验证老师token

            return true;
        } catch (InvalidClaimException e) {
            throw new RuntimeException("失效的payload");
        } catch (Exception e) {
            throw new RuntimeException("token无效");
        }

    }

}
